package cn.itsource.desktop.fallback;

import cn.itsource.desktop.api.LoginApi;
import cn.itsource.desktop.pojo.param.LoginFound;
import cn.itsource.desktop.pojo.param.LoginUpdate;
import cn.itsource.result.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class LoginApiFallback implements FallbackFactory<LoginApi> {
    @Override
    public LoginApi create(Throwable cause) {
        return new LoginApi(){
            @Override
            public JSONResult create(LoginFound login) {

                log.error("LoginApi 调用失败：{}", cause.getMessage(), cause);
                return JSONResult.error("服务调用失败["+cause.getMessage()+"]");
            }

            @Override
            public JSONResult update(LoginUpdate login) {
                log.error("LoginUpdate 调用失败：{}", cause.getMessage(), cause);
                return JSONResult.error("服务调用失败["+cause.getMessage()+"]");
            }
        };
    }
}
